import Taro from "@tarojs/taro";
import {View, Text} from "@tarojs/components";
import "./my-collect.less";
import {AtListItem} from "taro-ui";
import Api from "../../api/api";
import NavBar from "../../commponents/nav-bar/nav-bar";
import {getGlobal} from "../../api/globalData";

export default class MyCollect extends Taro.Component {
  constructor(props) {
    super(props);
    this.state = {
      subjectList: []
    };
  }

  config = {};

  componentWillMount() {
  }

  componentDidMount() {
    this.getSubjectList();
  }

  async getSubjectList() {
    let res = await Api.personSubject(null, 1);
    let data = res.data;
    if (data.success) {
      let list = data.data.list;
      this.setState({subjectList: list});
    }
  }

  toDetail(item) {
    Taro.navigateTo({
      url: `/pages/collect-detail/collect-detail?subjectId=${item.id}`
    });
  }

  render() {
    return (
      <View>
        <NavBar title='我的收藏夹'/>
        <View className="my-collect">
          {this.state.subjectList.map((item, index) => {
            return (
              <View key={item.id}>
                <AtList>
                  <AtListItem
                    title={item.name}
                    note={`${item.postNum}篇文章`}
                    arrow="right"
                    onClick={this.toDetail.bind(this, item)}
                  />
                </AtList>
              </View>
            );
          })}
        </View>
      </View>
    );
  }
}
